package cn.ffcs.uec.salary.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import cn.ffcs.uec.salary.dao.UecWaCrtDao;
import cn.ffcs.uec.salary.model.UecWaCrt;
import cn.ffcs.uom.common.constants.BaseUnitConstants;
import cn.ffcs.uom.common.dao.BaseDaoImpl;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Repository("uecWaCrtDao")
@Transactional
public class UecWaCrtDaoImpl extends BaseDaoImpl implements UecWaCrtDao {

	@Override
	public PageInfo queryPageInfoByUecWaCrt(UecWaCrt uecWaCrt, int current, int pageSize) {
		if (null != uecWaCrt) {
			if (!StrUtil.isNullOrEmpty(uecWaCrt.getPostGrade())) {
				StringBuilder sb = new StringBuilder(
						" SELECT * FROM UEC_WA_CRT T WHERE T.STATUS_CD = ? AND T.POST_GRADE = ? ");
				List<Object> params = new ArrayList<Object>();
				params.add(BaseUnitConstants.ENTT_STATE_ACTIVE);
				params.add(uecWaCrt.getPostGrade());
				return this.jdbcFindPageInfo(sb.toString(), params, current, pageSize, UecWaCrt.class);
			}
		}
		return null;
	}

	@Override
	public UecWaCrt findObjectByUecWaCrt(UecWaCrt uecWaCrt) {
		StringBuilder sb = new StringBuilder(
				" SELECT * FROM UEC_WA_CRT T WHERE T.STATUS_CD = ? ");
		List<Object> params = new ArrayList<Object>();
		params.add(BaseUnitConstants.ENTT_STATE_ACTIVE);
		if(null != uecWaCrt) {
			if(!StrUtil.isNullOrEmpty(uecWaCrt.getPostGrade())) {
				sb.append(" AND T.POST_GRADE = ? ");
				params.add(uecWaCrt.getPostGrade());
			}
			if (!StrUtil.isNullOrEmpty(uecWaCrt.getSalaryGrade())) {
				sb.append(" AND T.SALARY_GRADE = ? ");
				params.add(uecWaCrt.getSalaryGrade());
			}
			List<UecWaCrt> UecWaCrtList = this.jdbcFindList(sb.toString(), params, UecWaCrt.class);
			if (UecWaCrtList.size() > 0) {
				return UecWaCrtList.get(0);
			}
		}
		return null;
	}

}
